unit RclStr;

interface

uses
  JclStrings;

type
  Str = class
  private
  protected
  public
    class procedure Add(var S: string; const S1: string);
    class function EndsWith(aStr, aSubStr: string): Boolean;
    class function Find(const Substr: string; const S: string; const Index: Integer
        = 1): Integer;
    class function IsEmpty(S: string): Boolean;
    class function IsEqual(S1, S2: string): Boolean;
    class function LastPos(SubStr, S: string): Integer;
    class function Match(const SubStr, S: string; const Index: Integer = 1):
        Integer;
    class procedure Replace(var S: string; const Search, Replace: string);
    class function StartsWith(aStr, aSubStr: string): Boolean;
    class function StrToken(var S: AnsiString; Separator: AnsiChar): AnsiString;
    class function SubString(const S: string; Start: Integer; Count: Integer = -1):
        string;
    class function ToBool(S: string): Boolean;
  end;

implementation

uses
  SysUtils;

class procedure Str.Add(var S: string; const S1: string);
begin
  S := Format('%s%s', [S, S1]);
end;

class function Str.EndsWith(aStr, aSubStr: string): Boolean;
var
  S: string;
begin
  S := JclStrings.StrRight(aStr, Length(aSubStr));
  Result := JclStrings.StrSame(S, aSubStr);
end;

class function Str.Find(const Substr: string; const S: string; const Index:
    Integer = 1): Integer;
begin
  Result := JclStrings.StrFind(SubStr, S, Index);
end;

class function Str.IsEmpty(S: string): Boolean;
begin
  Result := JclStrings.StrSame(S, '');
end;

class function Str.IsEqual(S1, S2: string): Boolean;
begin
  Result := JclStrings.StrSame(S1, S2);
end;

class function Str.LastPos(SubStr, S: string): Integer;
begin
  Result := JclStrings.StrLastPos(SubStr, S);
end;

class function Str.Match(const SubStr, S: string; const Index: Integer = 1):
    Integer;
begin
  Result := JclStrings.StrMatch(SubStr, S, Index);
end;

class procedure Str.Replace(var S: string; const Search, Replace: string);
begin
  JclStrings.StrReplace(S, Search, Replace, [rfReplaceAll, rfIgnoreCase]);
end;

class function Str.StartsWith(aStr, aSubStr: string): Boolean;
var
  S: string;
begin
  S := JclStrings.StrLeft(aStr, Length(aSubStr));
  Result := JclStrings.StrSame(S, aSubStr);
end;

class function Str.StrToken(var S: AnsiString; Separator: AnsiChar): AnsiString;
begin
  Result := JclStrings.StrToken(S, Separator);
end;

class function Str.SubString(const S: string; Start: Integer; Count: Integer =
    -1): string;
begin
  if Count < 0 then
    Result := JclStrings.StrMid(S, Start, MaxInt)
  else
    Result := JclStrings.StrMid(S, Start, Count);
end;

class function Str.ToBool(S: string): Boolean;
begin
  Result := JclStrings.StrSame(S, 'T') or StrSame(S, 'True') or StrSame(S, '1');
end;

end.
